import React, { useState,useEffect } from 'react'
import {fetchgetcates} from '@/api'
import { Select } from 'antd';

const { Option } = Select;

// const cates = [
//   { id: 1, cate:'汽车生活' },
//   { id: 2, cate:'健身设备' },
//   { id: 3, cate:'保健食品' },
//   { id: 4, cate:'男装女装' },
// ]


  //二次封装的Select框
export default (props)=>{
  let [cates,setCates] = useState([])
useEffect(()=>{
  fetchgetcates().then(res=>{
    console.log(res.list);
    setCates(res.list)
   
    
  })
},[])

    
    return(
    <div className='af-select'>
        <Select defaultValue="" 
        style={{ width: 120 }} 
        allowClear
        onChange={(e)=>{props.onChange(e)}}
        >
            {
                cates.map(ele=>(
                <Option value={ele.cate} key = {ele._id}>{ele.cate_zh}
                </Option>
                ))
            }
            
        </Select>
    </div>

    )
}